package com.arch.dev.client.view;

import java.util.Set;

import com.arch.dev.client.controller.BudgetController;
import com.arch.dev.client.view.ui.BudgetImageBundle;
import com.arch.dev.client.view.ui.ImageButton;
import com.arch.dev.client.view.ui.PdfTable;
import com.arch.dev.client.vo.PdfVO;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.view.client.MultiSelectionModel;

public class PDFTableView extends Composite{

	private static PDFTableViewUiBinder uiBinder = GWT

	.create(PDFTableViewUiBinder.class);

	interface PDFTableViewUiBinder extends UiBinder<Widget, PDFTableView> {

	}
	ImageButton deleteImageButton = null;
	
	@UiField
	PdfTable pdfTable;

	public PdfTable getPdfTable() {

		return pdfTable;

	}

	@UiField
	Button generatePDF;

	public PDFTableView() {

		initWidget(uiBinder.createAndBindUi(this));

		BudgetImageBundle bundle = (BudgetImageBundle) GWT

				.create(BudgetImageBundle.class);
		
		deleteImageButton  = new ImageButton(null, bundle.getDeleteIcon());

		deleteImageButton.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {

				MultiSelectionModel<PdfVO> multiSelectionModel =  pdfTable.getMultiSelectionModel();

				Set<PdfVO> pdfVOs = multiSelectionModel.getSelectedSet();

				multiSelectionModel.clear();

			   BudgetController.getInstance().deletePdfValues(PDFTableView.this, pdfVOs);

			}

		});

		deleteImageButton.setTitle("Delete Records");
		
		pdfTable.addToolBarWidget(deleteImageButton);


	}

	public void addGeneratePDFClickHandler(ClickHandler handler) {

		generatePDF.addClickHandler(handler);

	}

}
